/*
 * $Id: $
 */
package org.rcgwt.client.ui.grid.internal;

import org.rcgwt.client.ui.grid.internal.model.IColumnModel;
import org.rcgwt.client.ui.grid.internal.model.IElementModel;
import org.rcgwt.client.ui.grid.internal.model.ITitleCellModel;
import org.rcgwt.client.ui.grid.internal.model.ITitleRowModel;

/**
 * 
 * @author Olivier Oeuillot (latest modification by $Author: $)
 * @version $Revision: $ $Date: $
 */
public class TitleCellModel extends AbstractElementModel implements
        ITitleCellModel {

    protected IColumnModel columnModel;

    protected ITitleRowModel titleRow;

    protected TitleCellModel(IColumnModel columnModel, ITitleRowModel titleRow) {
        this.modelIndex = columnModel.getModelIndex();
        this.columnModel = columnModel;
        this.titleRow = titleRow;
    }

    @Override
    public Type getType() {
        return Type.TITLE_CELL;
    }

    public IColumnModel getColumnModel() {
        return columnModel;
    }

    public ITitleRowModel getTitleRow() {
        return titleRow;
    }

    @Override
    public IElementModel getParent() {
        return getTitleRow();
    }

    @Override
    public String toString() {
        return "[TitleCell modelIndex=" + modelIndex + " state=0x"
                + Integer.toHexString(stateMask) + " column='"
                + getColumnModel() + "' titleRow='" + titleRow + "']";
    }

    @Override
    public void constructKey(IKey key) {
        super.constructKey(key);

        key.add("column");
        columnModel.appendKey(key);

        key.add("titleRow");
        titleRow.appendKey(key);
    }

}